<template>
	<view class="jobList">
		<view v-if="jobList.length==0">
			<u-empty ></u-empty>
		</view>
		<view>
			<u-button type="primary" @click="jumpAddInfo()" icon="plus">发布招聘</u-button>
		</view>
		<view>
			<JobCard @goJobDetail="goJobDetail(item)" v-for="(item,index) in jobList" :key="index" :jobInfo="item" />
		</view>
		
	</view>
</template>

<script>
	import JobCard from '../../components/jobCard.vue'
	import {findByUserId} from '../../api/enterprise.js'
	import {
		findRecruitmentInfo
	} from '../../api/index.js'
	import {
		Toast
	} from '../../common/common.js'
	export default {
		components: {
			JobCard,
		},
		data() {
			return {
				jobList: []
			}
		},
		methods: {
			findRecruitmentInfoFun() {
				let user = uni.getStorageSync("user");
				findRecruitmentInfo({
					'id': user.id
				}).then(res => {
					this.jobList = res.data.data;
				})
			},
			goJobDetail(item){
				uni.navigateTo({
					url:`/pageB/editorRecruitmentInfo/editorRecruitmentInfo?jobId=${item.id}`
				})
			},
			jumpAddInfo(){
				let user = uni.getStorageSync("user");
				findByUserId({"id":user.id}).then(res=>{
					if(res.data.data.length<=0){
						Toast({title:"当前用户下没用可以用于发布招聘消息的企业,请先添加企业"})
					}else{
						uni.navigateTo({
							url:"/pageB/addInfo/addInfo"
						})
					}
				})
				
			}
		},
		onLoad() {
			this.findRecruitmentInfoFun()
		},
		onShow(){
			this.findRecruitmentInfoFun()
		}
	}
</script>

<style>
.jobList {
		background: #f4f4f4;
		min-height: 100vh;
	}
</style>
